import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'

Vue.use(VueRouter)
/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('@/views/redirect/index')
            }
        ]
    },
    {
        path: '/login',
        component: () => import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () => import('@/views/login/auth-redirect'),
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/views/error-page/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () => import('@/views/error-page/401'),
        hidden: true
    },
    {
        path: '/profile',
        component: Layout,
        redirect: '/profile/profile',
        hidden: true,
        children: [
            {
                path: '/profile',
                component: () => import('@/views/profile/index'),
                hidden: true
            },
        ]
    },
    {
        path: '/',
        component: Layout,
        redirect: '/',
        name: 'Dashboard',
        icon: 'desktop-mac',
        children: [
            {
                path: '/',
                component: () => import('@/views/dashboard/index'),
                name: 'Dashboard',
                icon: 'desktop-mac', affix: true,
            },
        ]
    },
    {
        path: '/menus',
        component: Layout,
        redirect: '/menus/',
        name: '多级菜单',
        icon: 'tree',
        children: [
            {
                path: '/menus/1-1',
                component: () => import('@/views/examples/table'),
                name: '1-1',
                icon: 'table', affix: false,
                children: [
                    {
                        path: '/menus/1-1',
                        component: () => import('@/views/examples/table'),
                        name: '1-1-1',
                        icon: 'table', affix: false,
                        children: [
                            {
                                path: '/menus/1-1',
                                component: () => import('@/views/examples/table'),
                                name: '1-1-1-1',
                                icon: 'table', affix: false,
                            },
                            {
                                path: '/examples/table',
                                component: () => import('@/views/examples/table'),
                                name: '1-1-1-2',
                                icon: 'table', affix: false,
                            },
                        ]
                    },
                    {
                        path: '/examples/table',
                        component: () => import('@/views/examples/table'),
                        name: '1-1-2',
                        icon: 'table', affix: false,
                    },
                ]
            },
            {
                path: '/examples/table',
                component: () => import('@/views/examples/table'),
                name: '1-2',
                icon: 'table', affix: false,
            },
        ]
    },
    {
        path: '/examples',
        component: Layout,
        redirect: '/examples/table',
        name: 'Examples',
        icon: 'table',
        children: [
            {
                path: '/examples/table',
                component: () => import('@/views/examples/table'),
                name: '表格 Table',
                icon: 'table', affix: false,
            },
            {
                path: '/examples/button',
                component: () => import('@/views/examples/button'),
                name: '按钮 Button',
                icon: 'table', affix: true,
            },
            {
                path: '/examples/icons',
                component: () => import('@/views/examples/icons'),
                name: '图标 Icon',
                icon: 'text', affix: true,
            },
            {
                path: '/examples/card',
                component: () => import('@/views/examples/card'),
                name: '卡片 Card',
                icon: 'text', affix: true,
            },
            {
                path: '/examples/tabs',
                component: () => import('@/views/examples/tabs'),
                name: '卡片 Tabs',
                icon: 'text', affix: true,
            },
            {
                path: '/examples/toast',
                component: () => import('@/views/examples/toast'),
                name: '轻提示 Toast',
                icon: 'text', affix: true,
            },
            {
                path: '/examples/message',
                component: () => import('@/views/examples/message'),
                name: '信息 Message',
                icon: 'text', affix: true,
            },
        ]
    },
    {
        path: '/system',
        component: Layout,
        redirect: '/system/user',
        name: '系统管理',
        icon: 'table',
        children: [
            {
                path: '/system/user',
                component: () => import('@/views/system/user'),
                name: '用户管理',
                icon: 'table', affix: true,
                updateMark: true
            },
            {
                path: '/system/role',
                component: () => import('@/views/system/role'),
                name: '角色管理',
                icon: 'table', affix: true,
            },
            {
                path: '/system/post',
                component: () => import('@/views/system/post'),
                name: '岗位管理',
                icon: 'table', affix: true,
            },
            {
                path: '/system/dept',
                component: () => import('@/views/system/dept'),
                name: '部门管理',
                icon: 'table', affix: true,
            },
            {
                path: '/system/menu',
                component: () => import('@/views/system/menu'),
                name: '菜单管理',
                icon: 'table', affix: true,
            },
        ]
    },
    {
        path: '/tool',
        component: Layout,
        redirect: '/tool/gen',
        name: '系统工具',
        icon: 'desktop-mac',
        children: [
            {
                path: '/tool/gen',
                component: () => import('@/views/tool/gen'),
                name: '代码生成',
                icon: 'alpha-v-box', affix: true,
                updateMark: true
            },
        ]
    },
    {path: '*', redirect: '/404', hidden: true}
]
export const asyncRoutes = []

const createRouter = () => new VueRouter({
    // mode: 'history', // require service support
    scrollBehavior: () => ({y: 0}),
    routes: constantRoutes
})
const router = createRouter()

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
